﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class ChanQuanZhiHuanXieYiQianShuControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        MPPersistence Persistence1;
        Panel panel1;
        TabControl tabConreol1;
        TabPage TabPage1, TabPage2, TabPage3, TabPage4, TabPage5, TabPage6, TabPage7, TabPage8, TabPage9, TabPage10, TabPage11;
        Label Label1;
        LinkButton LinkButton1;
        ImageButton ImageButton1;
        Button btnUpload, BtnSave, BtnBack, Button5, Button6, BtnZDDR, BtnTijiao, BtnCxTJ, BtnTJBA, BtnCXBA, Button1, btndel;
        
        public string userid = string.Empty;
        public string strPID = string.Empty;
        public string strZID = string.Empty;
        public string strFID = string.Empty;
        public string strTYPE = string.Empty;
        public string strID = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            InitControl();
            base.OnLoad(e);
            if (!base.Page.IsPostBack)
            {

                Persistence1.Table = "zs_cqzhxy";
                Persistence1.Key = "ID";
                Persistence1.KeyValue = strID;
                Persistence1.ConnStr = _EluZSDataProvider.GetConnectionString();
            }
            Persistence1.BindControl = panel1;
            BindData();
            IsLookPerson();
            
        }

        private void IsLookPerson()
        {
            string sql = "Select rolename from zs_role where id in (Select roleid from zs_user_in_role where userid = '" + userid + "')";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["rolename"].ToString().Equals("查看人员"))
                    {
                        Button btnSave = (Button)FindControl("btnSave");
                        btnSave.Visible = false;
                    }
                }
            }
        }


        protected void InitControl() {
            Persistence1 = (MPPersistence)FindControl("Persistence1");
            panel1 = (Panel)FindControl("panel1");
            Label1 = (Label)FindControl("Label1");
            tabConreol1 = (TabControl)panel1.FindControl("tabConreol1");
            TabPage1 = (TabPage)tabConreol1.FindControl("TabPage1");
            TabPage2 = (TabPage)tabConreol1.FindControl("TabPage2");
            TabPage3 = (TabPage)tabConreol1.FindControl("TabPage3");
            TabPage4 = (TabPage)tabConreol1.FindControl("TabPage4");
            TabPage5 = (TabPage)tabConreol1.FindControl("TabPage5");
            TabPage6 = (TabPage)tabConreol1.FindControl("TabPage6");
            TabPage7 = (TabPage)tabConreol1.FindControl("TabPage7");
            TabPage8 = (TabPage)tabConreol1.FindControl("TabPage8");
            TabPage9 = (TabPage)tabConreol1.FindControl("TabPage9");
            TabPage10 = (TabPage)tabConreol1.FindControl("TabPage10");
            TabPage11 = (TabPage)tabConreol1.FindControl("TabPage11");
            LinkButton1 = (LinkButton)FindControl("LinkButton1");
            ImageButton1 = (ImageButton)FindControl("ImageButton1");
            btnUpload = (Button)FindControl("btnUpload");
            BtnSave = (Button)FindControl("BtnSave");
            BtnBack = (Button)FindControl("BtnBack");
            Button5 = (Button)TabPage3.FindControl("Button5");
            Button6 = (Button)TabPage3.FindControl("Button6");
            BtnZDDR = (Button)FindControl("BtnZDDR");
            BtnTijiao = (Button)FindControl("BtnTijiao");
            BtnCxTJ = (Button)FindControl("BtnCxTJ");
            BtnTJBA = (Button)FindControl("BtnTJBA");
            BtnCXBA = (Button)FindControl("BtnCXBA");
            Button1 = (Button)FindControl("Button1"); 
            btndel = (Button)FindControl("Button1");

            LinkButton1.Click += new EventHandler(linkButton1_Click);
            ImageButton1.Click += new ImageClickEventHandler(ImageButton1_Click);
            btnUpload.Click += new EventHandler(BtnUpload_Click);
            BtnSave.Click += new EventHandler(BtnSave_Click);
            BtnBack.Click += new EventHandler(BtnBack_Click);
            Button5.Click+=new EventHandler(Button5_Click);
            Button6.Click+=new EventHandler(Button6_Click);
            BtnZDDR.Click += new EventHandler(BtnZDDR_Click);
            BtnTijiao.Click += new EventHandler(BtnTijiao_Click);
            BtnCxTJ.Click += new EventHandler(BtnCxTJ_Click);
            BtnTJBA.Click += new EventHandler(BtnTJBA_Click);
            BtnCXBA.Click += new EventHandler(BtnCXBA_Click);
            Button1.Click += new EventHandler(Button1_Click);
            btndel.Click += new EventHandler(btndel_Click);

            strPID = base.Page.Request["PID"];
            strZID = base.Page.Request["ZID"];
            strFID = base.Page.Request["FID"];
            strTYPE = base.Page.Request["type"];
            strID = base.Page.Request["ID"];
        }

        protected void btndel_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(strID))
            {
                string sql = "Delete From zs_hbhxy Where Id='" + strID + "'";
                _EluZSDataProvider.RunSqlNon(sql);
                Page.ClientScript.RegisterStartupScript(this.GetType(), "sctj1", "<script>alert(删除成功！);window.location.href('EditRoom.aspx?query=cqzh&pid=" + strPID + "&id=" + strFID + "&zid=" + strZID + "');</script>");
            }
        }

      
        protected override void OnPreRender(EventArgs e) {
            base.OnPreRender(e);
            TextBox txtTextBox6 = (TextBox)TabPage3.FindControl("txtTextBox6");
            TextBox txtTextBox7 = (TextBox)TabPage3.FindControl("txtTextBox7");
            TextBox txtTextBox8 = (TextBox)TabPage3.FindControl("txtTextBox8");
            TextBox txtTextBox9 = (TextBox)TabPage3.FindControl("txtTextBox9");
            TextBox txtTextBox10 = (TextBox)TabPage3.FindControl("txtTextBox10");
            TextBox txtTextBox11 = (TextBox)TabPage3.FindControl("txtTextBox11");
            TextBox txtTextBox12 = (TextBox)TabPage3.FindControl("txtTextBox12");
            TextBox txtTextBox13 = (TextBox)TabPage3.FindControl("txtTextBox13");
            TextBox txtTextBox14 = (TextBox)TabPage3.FindControl("txtTextBox14");
            TextBox txtTextBox15 = (TextBox)TabPage3.FindControl("txtTextBox15");
            TextBox txtTextBox16 = (TextBox)TabPage3.FindControl("txtTextBox16");
            TextBox txtTextBox17 = (TextBox)TabPage3.FindControl("txtTextBox17");
            TextBox txtIID = (TextBox)panel1.FindControl("txtIID");
            TextBox txtFID = (TextBox)panel1.FindControl("txtFID");
            TextBox txtCAN_SYNC = (TextBox)panel1.FindControl("txtCAN_SYNC");
            TextBox txtZSJDH = (TextBox)TabPage1.FindControl("txtZSJDH");
           
            if (!string.IsNullOrEmpty(strFID))
            {
                DataTable dt = _EluZSDataProvider.GetTable("Select 产权人,承租人,房屋坐落 From zs_zsperson Where Id In (Select zspid From zs_proloupan Where id In ('" + strFID.Replace(",", "','") + "'))");
                if (dt.Rows.Count > 0) 
                {
                    string strCQR = dt.Rows[0]["产权人"].ToString();
                    string strCZR = dt.Rows[0]["承租人"].ToString();
                    string strFWZL = dt.Rows[0]["房屋坐落"].ToString();
                    if (string.IsNullOrEmpty(txtTextBox7.Text)) { txtTextBox7.Text = strCQR; }
                    if (string.IsNullOrEmpty(txtTextBox13.Text)) { txtTextBox13.Text = strFWZL; }
                    if (string.IsNullOrEmpty(txtTextBox14.Text)) { txtTextBox14.Text = strCQR; }
                    if (string.IsNullOrEmpty(txtTextBox15.Text)) { txtTextBox15.Text = strCZR; }
                    if (string.IsNullOrEmpty(txtTextBox8.Text)) { txtTextBox8.Text = strCZR; }
                }  
            }

            if (!string.IsNullOrEmpty(strPID))
            {
                EluZSProvider.Project project = _EluZSDataProvider.GetProjectXX(strPID);
                if (string.IsNullOrEmpty(txtTextBox6.Text)) { txtTextBox6.Text = project.征收部门; }
                if (string.IsNullOrEmpty(txtTextBox12.Text)) { txtTextBox12.Text = project.区属; }
                if (string.IsNullOrEmpty(txtTextBox16.Text)) { txtTextBox16.Text ="乙"; }
                if (string.IsNullOrEmpty(txtTextBox17.Text)) { txtTextBox17.Text = project.评估机构; }
                string myzs = _EluZSDataProvider.GetSomeStr("zs_prono", "征收许可证号", "pid", strPID);
                if (string.IsNullOrEmpty(txtZSJDH.Text))
                {
                    txtZSJDH.Text = _EluZSDataProvider.GetSomeStr("zs_prono", "征收许可证号", "pid", strPID);
                }
                string tt1 = myzs.Replace("宁", "|");
                string tt2 = tt1.Replace("府征字（", "|");
                string tt3 = tt2.Replace("年第", "|");
                string tt4 = tt3.Replace("号）", "|");
                string tt5 = tt4.Replace("|", ",");
                String[] tt6 = tt5.Split(',');
                if (tt6.Length > 1)
                {
                    if (string.IsNullOrEmpty(txtTextBox9.Text)) { txtTextBox9.Text = tt6[1]; }
                    if (string.IsNullOrEmpty(txtTextBox10.Text)) { txtTextBox10.Text = tt6[2]; }
                    if (string.IsNullOrEmpty(txtTextBox11.Text)) { txtTextBox11.Text = tt6[3]; }
                }
            }
            if (string.IsNullOrEmpty(txtIID.Text)) { txtIID.Text = _EluZSDataProvider.GetXYIID(); }
            if (string.IsNullOrEmpty(txtFID.Text)) { txtFID.Text = strFID; }
            if (string.IsNullOrEmpty(strID)) { if (string.IsNullOrEmpty(txtFID.Text)) { txtCAN_SYNC.Text = "0"; } }
            
        }
        protected void BindData()
        {
            if (string.IsNullOrEmpty(strID))
            {
                ImageButton1.Visible = false;
                BtnTijiao.Visible = false;
                BtnCxTJ.Visible = false;
                BtnTJBA.Visible = false;
                BtnCXBA.Visible = false;
                LinkButton1.Visible = false;
                btnUpload.Visible = false;
                Button1.Visible = false;
                btndel.Visible = false;
            }
            else
            {
                if (_EluZSDataProvider.IsQZSBM(userid) && !_EluZSDataProvider.IsSZSB(userid) && !_EluZSDataProvider.IsNetZSAdmin(userid) && !_EluZSDataProvider.IsZSAdmin(userid))
                {
                    Button1.Visible = false;
                    BtnCXBA.Visible = false;
                    LinkButton1.Visible = false;
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "displaytr", "<script>displaytr();</script>");
                }
                if (_EluZSDataProvider.IsQXLRRY(userid))
                {
                    Button1.Visible = false;
                    BtnCxTJ.Visible = false;
                    BtnTJBA.Visible = false;
                    BtnCXBA.Visible = false;
                    LinkButton1.Visible = false;
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "displaytr", "<script>displaytr();</script>");
                }
                if (_EluZSDataProvider.IsQXZZ(userid))
                {
                    Button1.Visible = false;
                    BtnCXBA.Visible = false;
                    LinkButton1.Visible = false;
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "displaytr", "<script>displaytr();</script>");
                }
                if (_EluZSDataProvider.IsSZSB(userid)) 
                {
                    BtnTJBA.Visible = false;
                    BtnCxTJ.Visible = false;
                    BtnTijiao.Visible = false;
                    BtnSave.Visible = false;
                    BtnZDDR.Visible = false;
                }
                if (_EluZSDataProvider.IsSZSB(userid) || _EluZSDataProvider.IsNetZSAdmin(userid) || _EluZSDataProvider.IsZSAdmin(userid))
                {
                    DataTable strSSHZT = _EluZSDataProvider.GetTable("Select 审核状态,提交备案,市备案状态 From ZS_CQZHXY t Where Id='" + strID + "'");

                    if (strSSHZT.Rows.Count > 0)
                    {
                        if (strSSHZT.Rows[0]["审核状态"].ToString().Equals("1") && strSSHZT.Rows[0]["提交备案"].ToString().Equals("1") && strSSHZT.Rows[0]["市备案状态"].ToString().Equals("0"))
                        {
                            Button1.Enabled = true;
                            Button1.Text = "备案未通过";
                        }
                        if (strSSHZT.Rows[0]["审核状态"].ToString().Equals("1") && strSSHZT.Rows[0]["提交备案"].ToString().Equals("1") && strSSHZT.Rows[0]["市备案状态"].ToString().Equals("1"))
                        {
                            Button1.Enabled = true;
                            Button1.Text = "备案已通过";
                        }
                        if (!strSSHZT.Rows[0]["审核状态"].ToString().Equals("1") || !strSSHZT.Rows[0]["提交备案"].ToString().Equals("1"))
                        {
                             Button1.Enabled = false;
                             Button1.Text = "备案未通过";
                        }
                    }
                }
                string strTJZT = _EluZSDataProvider.GetString("Select 审核状态 From ZS_CQZHXY t Where Id='"+strID+"'");
                string strBAZT = _EluZSDataProvider.GetString("Select 提交备案 From ZS_CQZHXY t Where Id='" + strID + "'");
                if (strTJZT == "0") 
                {
                    Label1.Text = "附件上传";
                    btnUpload.Text = "附件上传";
                    Button5.Text = "附件上传";
                    Button6.Text = "附件上传";
                    BtnSave.Enabled = true;
                    BtnTijiao.Enabled = true;
                    BtnCxTJ.Enabled = false;
                    BtnTJBA.Enabled = false;
                    BtnCXBA.Enabled = false;
                }
                else if (strTJZT == "1")
                {
                    Label1.Text = "附件列表";
                    btnUpload.Text = "附件列表";
                    Button5.Text = "附件列表";
                    Button6.Text = "附件列表";
                    BtnSave.Enabled = false;
                    BtnTijiao.Enabled = false;
                    BtnCxTJ.Enabled = true;
                    BtnTJBA.Enabled = true;
                    BtnCXBA.Enabled = false;

                    if (strBAZT == "0")
                    {
                        Label1.Text = "附件列表";
                        btnUpload.Text = "附件列表";
                        Button5.Text = "附件列表";
                        Button6.Text = "附件列表";
                        BtnSave.Enabled = false;
                        BtnTijiao.Enabled = false;
                        BtnCxTJ.Enabled = true;
                        BtnTJBA.Enabled = true;
                        BtnCXBA.Enabled = false;
                    }
                    else if (strBAZT == "1")
                    {
                        Label1.Text = "附件列表";
                        btnUpload.Text = "附件列表";
                        Button5.Text = "附件列表";
                        Button6.Text = "附件列表";
                        BtnSave.Enabled = false;
                        BtnTijiao.Enabled = false;
                        BtnCxTJ.Enabled = false;
                        BtnTJBA.Enabled = false;
                        BtnCXBA.Enabled = true;
                    }
                }
            }
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnSave_Click(object sender, EventArgs e)
        {
            TextBox TextBox2 = (TextBox)TabPage1.FindControl("txtTextBox2");
            if (TextBox2.Text.Trim() == "")
            {


                string sql1 = @"Select (Case When length(to_char(nvl(Max(最大顺序号),0)*1+1))=1 Then 
                            '000'||to_char(nvl(Max(最大顺序号),0)*1+1) 
                            When length(nvl(Max(最大顺序号),0)*1+1)=2 Then 
                            '00'||to_char(nvl(Max(最大顺序号),0)*1+1) 
                            When length(nvl(Max(最大顺序号),0)*1+1)=3 Then 
                            '0'||to_char(nvl(Max(最大顺序号),0)*1+1) 
                            Else to_char(nvl(Max(最大顺序号),0)*1+1) End
                            ) 顺序号
                            From (Select Max(最大顺序号) 最大顺序号 From 
                            (Select Max(textbox1) 最大顺序号 From zs_hbhxy 
                             Where  pnid In (Select Id From zs_prono Where pId='" + Page.Request["PID"] + @"')
                             Union All 
                             Select Max(textbox2) 最大顺序号 From zs_cqzhxy 
                             Where fid In (
                             Select Id From zs_proloupan Where pid In(Select pid From zs_prono Where id='" + Page.Request["PID"] + @"'))))";
                string num = _EluZSDataProvider.GetString(sql1);
                TextBox2.Text = num;
            }
            for (int i = 0; i < TabPage3.Controls.Count; i++)
            {
                if (TabPage3.Controls[i] is TextBox)
                {
                    if (string.IsNullOrEmpty((TabPage3.Controls[i] as TextBox).Text.Trim()))
                    {
                        (TabPage3.Controls[i] as TextBox).Text = "\\";
                    }
                }
            }
            for (int i = 0; i < TabPage5.Controls.Count; i++)
            {
                if (TabPage5.Controls[i] is TextBox)
                {
                    if (string.IsNullOrEmpty((TabPage5.Controls[i] as TextBox).Text.Trim()))
                    {
                        (TabPage5.Controls[i] as TextBox).Text = "\\";
                    }
                }
            }
            for (int i = 0; i < TabPage8.Controls.Count; i++)
            {
                if (TabPage8.Controls[i] is TextBox)
                {
                    if (string.IsNullOrEmpty((TabPage8.Controls[i] as TextBox).Text.Trim()))
                    {
                        (TabPage8.Controls[i] as TextBox).Text = "\\";
                    }
                }
            }
            for (int i = 0; i < TabPage10.Controls.Count; i++)
            {
                if (TabPage10.Controls[i] is TextBox)
                {
                    if (string.IsNullOrEmpty((TabPage10.Controls[i] as TextBox).Text.Trim()))
                    {
                        (TabPage10.Controls[i] as TextBox).Text = "\\";
                    }
                }
            }
            Persistence1.Update();
            base.Page.Response.Redirect("ChanQuanZhiHuanXieYiQianShu.aspx?ID=" + Persistence1.KeyValue + "&PID=" + strPID + "&ZID=" + strZID + "&FID=" + strFID + "&&action=edit&type=" + strTYPE + "");
            
        }
        /// <summary>
        /// 协议附件上传
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnUpload_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Persistence1.KeyValue))
            {
                string strScript = string.Format("<script>OpenFileUpload('{0}','{1}','{2}','{3}');</script>", "101",
                    Persistence1.KeyValue, HttpContext.Current.Request["ID"].Trim(), HttpContext.Current.Request["PID"].Trim());
                Page.ClientScript.RegisterStartupScript(this.GetType(), "opennew", strScript);
            }
        }
        /// <summary>
        /// 返回事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnBack_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(strPID))
            {
                if (!string.IsNullOrEmpty(strZID))
                {
                    HttpContext.Current.Response.Redirect("ProLoupan.aspx?PID=" + strPID + "&ZID=" + strZID + "&query=cqzh");
                }
                if (!string.IsNullOrEmpty(strTYPE))
                {
                    if (strTYPE == "1")
                    {
                        HttpContext.Current.Response.Redirect("FangSan.aspx?PID=" + strPID + "&query=cqzh");
                    }
                }
            }
        }
        /// <summary>
        /// 其他附件上传
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button5_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Persistence1.KeyValue))
            {
                string strScript = string.Format("<script>OpenFileUpload('{0}','{1}','{2}','{3}');</script>", "1011",
                    Persistence1.KeyValue, strID, strPID);
                Page.ClientScript.RegisterStartupScript(this.GetType(), "opennew", strScript);
            }
        }
        /// <summary>
        /// 其他附件上传
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button6_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Persistence1.KeyValue))
            {
                string strScript = string.Format("<script>OpenFileUpload('{0}','{1}','{2}','{3}');</script>", "1012",
                    Persistence1.KeyValue, strID, strPID);
                Page.ClientScript.RegisterStartupScript(this.GetType(), "opennew", strScript);
            }
        }
        /// <summary>
        /// 打印按钮--FID
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ImageButton1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(strID))
            {
                int tt = Convert.ToInt32(_EluZSDataProvider.GetSomeStr("zs_cqzhxy", "打印次数", "id", strID));
                string temp = (tt + 1).ToString();
                _EluZSDataProvider.UpdateSomething("zs_cqzhxy", "打印次数", temp, "id", strID);
                _EluZSDataProvider.InsertSomething("ZS_XYDYRY", "xyid,userid,type", string.Format("'{0}','{1}','0'", strID,userid));
                string strScript = string.Format("<script>openPrint('{0}','{1}');</script>", strFID, strID);
                Page.ClientScript.RegisterStartupScript(this.GetType(), "openPrint", strScript);
            }
        }
        /// <summary>
        /// 打印人员留痕-多个ID
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void linkButton1_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Redirect("ZS_DYRYLH.aspx?PID=" + strPID + "&ZID=" + strZID + "&ID=" + strID + "&FID=" + strFID + "&action=edit&type=0");
        }
        /// <summary>
        /// 自动代入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnZDDR_Click(object sender, EventArgs e)
        {
            TextBox txtTextBox58 = (TextBox)TabPage3.FindControl("txtTextBox58");//房屋坐落
            TextBox txtTextBox59 = (TextBox)TabPage3.FindControl("txtTextBox59");//土地分摊面积
            TextBox txtTextBox60 = (TextBox)TabPage3.FindControl("txtTextBox60");//zs_zsperson ADDTIME,YEAR
            TextBox txtTextBox61 = (TextBox)TabPage3.FindControl("txtTextBox61");//zs_zsperson ADDTIME,Month
            TextBox txtTextBox62 = (TextBox)TabPage3.FindControl("txtTextBox62");//zs_zsperson ADDTIME,Day
            TextBox txtTextBox103 = (TextBox)TabPage5.FindControl("txtTextBox103");//房屋结构
            TextBox txtTextBox104 = (TextBox)TabPage5.FindControl("txtTextBox104");//房屋用途
            TextBox txtTextBox26 = (TextBox)TabPage3.FindControl("txtTextBox26");//房屋建筑面积 -- 拆迁补助费
            TextBox txtTextBox19 = (TextBox)TabPage3.FindControl("txtTextBox19");//总补偿款
            TextBox txtTextBox21 = (TextBox)TabPage3.FindControl("txtTextBox21");//总补偿款
            TextBox txtTextBox23 = (TextBox)TabPage3.FindControl("txtTextBox23");//产权人补偿款
            TextBox txtTextBox25 = (TextBox)TabPage3.FindControl("txtTextBox25");//承租人补偿款
            TextBox txtTextBox17 = (TextBox)TabPage3.FindControl("txtTextBox17");//评估金额
            TextBox txtTextBox170 = (TextBox)TabPage3.FindControl("txtTextBox170");//评估金额
            TextBox txtTextBox129 = (TextBox)TabPage8.FindControl("txtTextBox129");
            TextBox txtTextBox132 = (TextBox)TabPage8.FindControl("txtTextBox132");
            TextBox txtTextBox131 = (TextBox)TabPage8.FindControl("txtTextBox131");
            TextBox txtTextBox133 = (TextBox)TabPage8.FindControl("txtTextBox133");
            TextBox txtTextBox134 = (TextBox)TabPage8.FindControl("txtTextBox134");
            TextBox txtTextBox136 = (TextBox)TabPage8.FindControl("txtTextBox136");
            TextBox txtTextBox120 = (TextBox)TabPage5.FindControl("txtTextBox120");
            TextBox txtTextBox108 = (TextBox)TabPage5.FindControl("txtTextBox108");
            TextBox txtTextBox109 = (TextBox)TabPage5.FindControl("txtTextBox109");

            TextBox txtTextBox53 = (TextBox)TabPage3.FindControl("txtTextBox53");
            TextBox txtTextBox63 = (TextBox)TabPage3.FindControl("txtTextBox63");
            TextBox txtTextBox64 = (TextBox)TabPage3.FindControl("txtTextBox64");
            TextBox txtTextBox74 = (TextBox)TabPage3.FindControl("txtTextBox74");
            TextBox txtTextBox99 = (TextBox)TabPage3.FindControl("txtTextBox99");
            TextBox txtTextBox100 = (TextBox)TabPage3.FindControl("txtTextBox100");
            TextBox txtTextBox101 = (TextBox)TabPage3.FindControl("txtTextBox101");
            TextBox txtTextBox102 = (TextBox)TabPage3.FindControl("txtTextBox102");
            TextBox txtTextBox143 = (TextBox)TabPage10.FindControl("txtTextBox143");
            string strPid = base.Page.Request["PID"];
            if (!string.IsNullOrEmpty(strFID))
            {
                DataTable dt = _EluZSDataProvider.GetTable("Select id,房屋坐落,土地分摊面积,房屋结构,房屋用途,ADDTIME,to_number(nvl(replace(房屋建筑面积,'\\',''),0)) 房屋建筑面积 From zs_zsperson Where Id In (Select zspid From zs_proloupan Where id In ('" + strFID.Replace(",", "','") + "'))");
                if (dt.Rows.Count > 0) 
                {
                    string strZSPID = dt.Rows[0]["ID"].ToString();
                    #region 产权人补偿款、承租人补偿款
                    if (!string.IsNullOrEmpty(strZSPID) && !string.IsNullOrEmpty(strPID))
                    {
                        string strCQRBCK = _EluZSDataProvider.GetString(@"Select nvl(Sum(to_number(nvl(replace(ZZ产权人补偿款,'\\',''),0))+
to_number(nvl(replace(YY产权人补偿款,'\\',''),0))+
to_number(nvl(replace(FYY产权人补偿款,'\\',''),0))+
to_number(nvl(replace(ZGF产权人补偿款,'\\',''),0))),0) 产权人补偿款
From zs_zzbcjfenhu Where pid In(Select Id From zs_prono Where pid='" + strPID + "') And zspid='" + strZSPID + "'");
                        string strCZRBCK = _EluZSDataProvider.GetString(@"Select nvl(Sum(to_number(nvl(replace(ZZ承租人补偿款,'\\',''),0))+
to_number(nvl(replace(YY承租人补偿款,'\\',''),0))+
to_number(nvl(replace(FYY承租人补偿款,'\\',''),0))+
to_number(nvl(replace(ZGF承租人补偿款,'\\',''),0))),0) 承租人补偿款
From zs_zzbcjfenhu Where pid In(Select Id From zs_prono Where pid='" + strPID + "') And zspid='" + strZSPID + "'");
                        string strZBCK = _EluZSDataProvider.GetString(@"Select nvl(sum(to_number(nvl(replace(ZZ产权人补偿款,'\\',''),0))+
to_number(nvl(replace(YY产权人补偿款,'\\',''),0))+
to_number(nvl(replace(FYY产权人补偿款,'\\',''),0))+
to_number(nvl(replace(ZGF产权人补偿款,'\\',''),0))+
to_number(nvl(replace(ZZ承租人补偿款,'\\',''),0))+
to_number(nvl(replace(YY承租人补偿款,'\\',''),0))+
to_number(nvl(replace(FYY承租人补偿款,'\\',''),0))+
to_number(nvl(replace(ZGF承租人补偿款,'\\',''),0))),0) 总补偿款
From zs_zzbcjfenhu Where pid In(Select Id From zs_prono Where pid='" + strPID + "') And zspid='" + strZSPID + "'");
                        if (string.IsNullOrEmpty(txtTextBox23.Text.Trim()))
                        {
                            txtTextBox23.Text = strCQRBCK;
                            base.Page.ClientScript.RegisterStartupScript(this.GetType(), "1", "<script>SetCQMoneyRelation('txtTextBox23','txtTextBox22')</script>");
                        }
                        if (string.IsNullOrEmpty(txtTextBox25.Text.Trim()))
                        {
                            txtTextBox25.Text = strCZRBCK;
                            base.Page.ClientScript.RegisterStartupScript(this.GetType(), "2", "<script>SetCQMoneyRelation('txtTextBox25','txtTextBox24')</script>");
                        }
                        if (string.IsNullOrEmpty(txtTextBox19.Text.Trim()))
                        {
                            txtTextBox19.Text = strZBCK;
                            base.Page.ClientScript.RegisterStartupScript(this.GetType(), "3", "<script>SetCQMoneyRelation('txtTextBox19','txtTextBox18')</script>");
                        }
                        if (string.IsNullOrEmpty(txtTextBox21.Text.Trim()))
                        {
                            txtTextBox21.Text = strZBCK;
                            base.Page.ClientScript.RegisterStartupScript(this.GetType(), "4", "<script>SetCQMoneyRelation('txtTextBox21','txtTextBox20')</script>");
                        }
                    }
                    DataTable dtxiu = _EluZSDataProvider.GetTable("Select ZS室内装饰装修评估补偿金额合计 As 装修 From zs_zzbcjfenhu Where pid In(Select Id From zs_prono Where pid='" + strPID + "') And zspid='" + strZSPID + "'"); //此处为装修评估信息
                    if (string.IsNullOrEmpty(txtTextBox170.Text.Trim()))
                    {
                        txtTextBox170.Text = dtxiu.Rows[0]["装修"].ToString();
                    } //此处为产权调换房的房源信息
                    #endregion
                    #region 房屋坐落、土地分摊面积、房屋结构、房屋用途、ADDTIME、拆迁补助费(房屋建筑面积) //此处为产权调换房的房源信息
                    DataTable dtfang = _EluZSDataProvider.GetTable("Select 楼层号,房间号,房型,建筑面积,楼层房间号 From ZS_PROLOUPAN Where Id='" + strFID + "'"); //此处为产权调换房的房源信息
                    DataTable dtzhuang = _EluZSDataProvider.GetTable("Select 楼盘名称||幢号||'幢' As 坐落 From zs_prozhuang Where Id='" + strZID + "'"); //此处为产权调换房的房源信息
                    if (string.IsNullOrEmpty(txtTextBox58.Text.Trim())) { 
                        txtTextBox58.Text = dtzhuang.Rows[0]["坐落"].ToString() + dtfang.Rows[0]["楼层房间号"].ToString() + "号";
                    } //此处为产权调换房的房源信息
                    if (string.IsNullOrEmpty(txtTextBox129.Text.Trim()))
                    {
                        txtTextBox129.Text = dtzhuang.Rows[0]["坐落"].ToString() + dtfang.Rows[0]["楼层房间号"].ToString() + "号";
                    } //此处为产权调换房的房源信息
                    if (string.IsNullOrEmpty(txtTextBox59.Text.Trim())) {
                        txtTextBox59.Text = dtfang.Rows[0]["建筑面积"].ToString(); 
                    } //此处为产权调换房的房源信息
                    if (string.IsNullOrEmpty(txtTextBox132.Text.Trim()))
                    {
                        txtTextBox132.Text = dtfang.Rows[0]["楼层号"].ToString();
                    } //此处为产权调换房的房源信息
                    if (string.IsNullOrEmpty(txtTextBox133.Text.Trim()))
                    {
                        txtTextBox133.Text = dtfang.Rows[0]["建筑面积"].ToString();
                    } //此处为产权调换房的房源信息
                    if (string.IsNullOrEmpty(txtTextBox134.Text.Trim()))
                    {
                        txtTextBox134.Text = dtfang.Rows[0]["建筑面积"].ToString();
                    } //此处为产权调换房的房源信息
                    if (string.IsNullOrEmpty(txtTextBox136.Text.Trim()))
                    {
                        txtTextBox136.Text ="期";
                    } //此处为产权调换房的房源信息
                    if (string.IsNullOrEmpty(txtTextBox131.Text.Trim()))
                    {
                        txtTextBox131.Text = "住宅";
                    } //此处为产权调换房的房源信息
                    if (string.IsNullOrEmpty(txtTextBox53.Text.Trim()))
                    {
                        txtTextBox53.Text = "乙";
                    }
                    if (string.IsNullOrEmpty(txtTextBox63.Text.Trim()))
                    {
                        txtTextBox63.Text = "乙";
                    }
                    if (string.IsNullOrEmpty(txtTextBox64.Text.Trim()))
                    {
                        txtTextBox64.Text = "乙";
                    }
                    if (string.IsNullOrEmpty(txtTextBox74.Text.Trim()))
                    {
                        txtTextBox74.Text = "乙";
                    }
                    if (string.IsNullOrEmpty(txtTextBox99.Text.Trim()))
                    {
                        txtTextBox99.Text = "肆";
                    }
                    if (string.IsNullOrEmpty(txtTextBox100.Text.Trim()))
                    {
                        txtTextBox100.Text = "叁";
                    }
                    if (string.IsNullOrEmpty(txtTextBox101.Text.Trim()))
                    {
                        txtTextBox101.Text = "壹";
                    }
                    if (!string.IsNullOrEmpty(strZSPID))
                    {
                        if (string.IsNullOrEmpty(txtTextBox143.Text.Trim())) { txtTextBox143.Text = _EluZSDataProvider.GetString("Select 证件号 From zs_zsperson Where Id='" + strZSPID + "'"); }
                    }

                    if (string.IsNullOrEmpty(txtTextBox103.Text.Trim())) 
                    {
                        string sql3 = "Select keyname From zs_params Where Name='结构等级' And keyvalue='" + dt.Rows[0]["房屋结构"].ToString() + "'";
                        txtTextBox103.Text = _EluZSDataProvider.GetString(sql3); 
                    }
                    if (string.IsNullOrEmpty(txtTextBox104.Text.Trim())) 
                    {
                        string sql3 = "Select keyname From zs_params Where Name='房屋用途' And keyvalue='" + dt.Rows[0]["房屋用途"].ToString() + "'";
                        txtTextBox104.Text = _EluZSDataProvider.GetString(sql3); 
                    }
                    string strFWJZMJ = dt.Rows[0]["房屋建筑面积"].ToString();

                    if (string.IsNullOrEmpty(txtTextBox108.Text.Trim())) { txtTextBox108.Text = dt.Rows[0]["房屋建筑面积"].ToString(); }//被征收房屋信息
                    if (string.IsNullOrEmpty(txtTextBox109.Text.Trim())) { txtTextBox109.Text = dt.Rows[0]["房屋建筑面积"].ToString(); }//被征收房屋信息
                    if (string.IsNullOrEmpty(txtTextBox120.Text.Trim())) { txtTextBox120.Text = dt.Rows[0]["土地分摊面积"].ToString(); }//被征收房屋信息
                    if (!string.IsNullOrEmpty(strFWJZMJ)) {
                        Double mj = Convert.ToDouble(strFWJZMJ);
                        Double jszq = (mj * 50);
                        if (jszq <= 1000)
                        {
                            jszq = 1000;
                        }
                        if (string.IsNullOrEmpty(txtTextBox26.Text.Trim())) { txtTextBox26.Text = jszq.ToString(); }
                    }
                    #endregion
                    #region 评估机构 甲乙方
                    if (!string.IsNullOrEmpty(strPid))
                    {
                        if (string.IsNullOrEmpty(txtTextBox17.Text.Trim())) { txtTextBox17.Text = _EluZSDataProvider.GetString("Select 单位名称 From zs_company Where Id=(Select comid From zs_pgbmjl Where 通过状态='1' And  pnid='"+strPid+"')"); }
                        //if (string.IsNullOrEmpty(txtTextBox94.Text.Trim())) { txtTextBox94.Text = _EluZSDataProvider.GetString("Select 征收部门 From zs_project Where Id In (Select pid From zs_prono Where Id='" + strPid + "')"); }
                    }
                    #endregion
                }
            }
        }
        /// <summary>
        /// 提交审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnTijiao_Click(object sender, EventArgs e)
        {
            _EluZSDataProvider.GetProjectZT("zs_cqzhxy", "审核状态", strID, "1");
            if (_EluZSDataProvider.CkFileCount(strPID, "101")) { _EluZSDataProvider.UpdateFileCS(strPID, "101"); }
            if (_EluZSDataProvider.CkFileCount(strPID, "1011")) { _EluZSDataProvider.UpdateFileCS(strPID, "1011"); }
            if (_EluZSDataProvider.CkFileCount(strPID, "1012")) { _EluZSDataProvider.UpdateFileCS(strPID, "1012"); }
            Label1.Text = "附件列表";
            btnUpload.Text = "附件列表";
            Button5.Text = "附件列表";
            Button6.Text = "附件列表";
            BtnSave.Enabled = false;
            BtnTijiao.Enabled = false;
            BtnCxTJ.Enabled = true;
            BtnTJBA.Enabled = true;
            BtnCXBA.Enabled = false;
        }
        /// <summary>
        /// 撤销提交审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnCxTJ_Click(object sender, EventArgs e)
        {
            _EluZSDataProvider.GetProjectZT("zs_cqzhxy", "审核状态", strID, "0");
            Label1.Text = "附件上传";
            btnUpload.Text = "附件上传";
            Button5.Text = "附件上传";
            Button6.Text = "附件上传";
            BtnSave.Enabled = true;
            BtnTijiao.Enabled = true;
            BtnCxTJ.Enabled = false;
            BtnTJBA.Enabled = false;
            BtnCXBA.Enabled = false;
        }
        /// <summary>
        /// 提交备案
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnTJBA_Click(object sender, EventArgs e)
        {
            _EluZSDataProvider.GetProjectZT("zs_cqzhxy", "提交备案", strID, "1");
            string sql = @"Update zs_cqzhxy
   Set TextBox3 = '" + DateTime.Now.Year + "',TextBox4 = '" + DateTime.Now.Month + "',TextBox5 = '" + DateTime.Now.Day + "' Where Id = '" + strID + "'";
            _EluZSDataProvider.RunSqlNon(sql);
            Label1.Text = "附件列表";
            btnUpload.Text = "附件列表";
            Button5.Text = "附件列表";
            Button6.Text = "附件列表";
            BtnSave.Enabled = false;
            BtnTijiao.Enabled = false;
            BtnCxTJ.Enabled = false;
            BtnTJBA.Enabled = false;
            BtnCXBA.Enabled = true;
            Button1.Enabled = true;
            Page.ClientScript.RegisterStartupScript(this.GetType(), "up", "<script>location.href = location.href;</script>");
        }
        /// <summary>
        /// 撤销备案
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnCXBA_Click(object sender, EventArgs e)
        {
            _EluZSDataProvider.GetProjectZT("zs_cqzhxy", "提交备案", strID, "0");
            string sql = @"Update zs_cqzhxy set TextBox3 = ' ',TextBox4 = ' ',TextBox5 = ' ' Where Id = '" + strID + "'";
            _EluZSDataProvider.RunSqlNon(sql);
            Label1.Text = "附件列表";
            btnUpload.Text = "附件列表";
            Button5.Text = "附件列表";
            Button6.Text = "附件列表";
            BtnSave.Enabled = false;
            BtnTijiao.Enabled = false;
            BtnCxTJ.Enabled = true;
            BtnTJBA.Enabled = true;
            BtnCXBA.Enabled = false;
            Page.ClientScript.RegisterStartupScript(this.GetType(), "up1", "<script>location.href = location.href;</script>");
        }


        /// <summary>
        /// 备案是否通过
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Button1.Text == "备案未通过")
            {
                _EluZSDataProvider.GetProjectZT("zs_cqzhxy", "市备案状态", strID, "1");
                Persistence1 = (MPPersistence)FindControl("Persistence1");
                panel1 = (Panel)FindControl("panel1");
                tabConreol1 = (TabControl)panel1.FindControl("tabConreol1");
                TabPage1 = (TabPage)tabConreol1.FindControl("TabPage1");
                TextBox txtTextBox3 = (TextBox)TabPage1.FindControl("txtTextBox3");
                if (string.IsNullOrEmpty(txtTextBox3.Text.Trim()))
                {
                    txtTextBox3.Text = System.DateTime.Now.Year.ToString();
                }
                TextBox txtTextBox4 = (TextBox)TabPage1.FindControl("txtTextBox4");
                if (string.IsNullOrEmpty(txtTextBox4.Text.Trim()))
                {
                    txtTextBox4.Text = System.DateTime.Now.Month.ToString();
                }
                TextBox txtTextBox5 = (TextBox)TabPage1.FindControl("txtTextBox5");
                if (string.IsNullOrEmpty(txtTextBox5.Text.Trim()))
                {
                    txtTextBox5.Text = System.DateTime.Now.Day.ToString();
                }
                Button1.Text = "备案已通过";
                return;
            }
            if (Button1.Text == "备案已通过")
            {
                _EluZSDataProvider.GetProjectZT("zs_cqzhxy", "市备案状态", strID, "0");
                Button1.Text = "备案未通过";
                return;
            }
        }
    }
}


